<?php 
/**
 * 图片的服务接口
 * @author Haiqin
 *
 */
namespace Common\Logic;
class MaterialImagesLogic{
	
	private $m;
	
	function __construct() {
		$this->m = D('MaterialImages');
	}
	
	/**
	 * 获取图片
	 * @param unknown $fkID
	 * @param unknown $fkGroup
	 * @return list
	 */
	public function get_images($fkID,$fkGroup){
		$map['fk_id'] = $fkID;
		$map['fk_group'] = $fkGroup;
		return $this->m->where($map)->select();
	}
	
	/**
	 * 统一的图片保存
	 * @param unknown $fkID
	 * @param unknown $fkGroup
	 * @param unknown $post 即$_POST参数
	 */
	public function save($fkID,$fkGroup,$post){
		$data['fk_id'] = $fkID;
		$data['fk_group'] = $fkGroup;
		$img_list_id = $post['img_list_id'];
		
		for($i = 0 ; $i < count($img_list_id) ; $i++){
			$data['img_id'] = $post['img_list_id'][$i] ;
			$data['title'] = $post['img_list_title'][$i];
			$data['alt'] = $post['img_list_alt'][$i];
			$data['redurl'] = $post['img_list_redurl'][$i];
			$data['target'] = $post['img_list_target'][$i];
			//$this->m->create($data);
			$this->m->save($data);
		}
	}
	
	/**
	 * 统一删除文件
	 * @param unknown $fkID
	 * @param unknown $fkGroup
	 * @return boolean
	 */
	public function del($fkID,$fkGroup){
		$map['fk_id'] = $fkID;
		$map['fk_group'] = $fkGroup;
		if($this->m->where($map)->delete()){
			return true;
		}else{
			return false;
		}
	}
}